<template>
	<div class="sys-menu-container">
		<el-card shadow="hover" :body-style="{ paddingBottom: '0' }">
			<el-form :model="state.queryParams" ref="queryForm" :inline="true">
				<el-form-item label="类型名称">
					<el-input v-model="state.queryParams.name" placeholder="类型名称" clearable />
				</el-form-item>
				<el-form-item label="类型编号">
					<el-input v-model="state.queryParams.code" placeholder="类型编号" clearable />
				</el-form-item>
				<el-form-item>
					<el-button-group>
						<el-button type="primary" icon="ele-Search" @click="handleQuery"> 查询 </el-button>
						<el-button icon="ele-Refresh" @click="resetQuery"> 重置 </el-button>
					</el-button-group>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" icon="ele-Plus" @click="openAddType"> 新增 </el-button>
				</el-form-item>
			</el-form>
		</el-card>
		<el-card class="full-table" shadow="hover" style="margin-top: 8px">
			<el-table :data="state.labelData" v-loading="state.loading" row-key="id" :tree-props="{ children: 'children', hasChildren: 'hasChildren' }" border>
				<el-table-column prop="id" label="编号" header-align="center" show-overflow-tooltip />
				<el-table-column prop="code" label="类型编码" header-align="center" show-overflow-tooltip />
				<el-table-column prop="name" label="类型名称" header-align="center" show-overflow-tooltip />
				<el-table-column prop="sort" label="排序" header-align="center" show-overflow-tooltip />
				<el-table-column label="操作" width="140" fixed="right" align="center" show-overflow-tooltip>
					<template #default="scope">
						<!-- v-auth="'cmsLabel:delete'" -->
						<el-button icon="ele-Edit" size="small" text type="primary" @click="openEditType(scope.row)"> 编辑 </el-button>
						<el-button icon="ele-Delete" size="small" text type="danger" @click="delType(scope.row)"> 删除 </el-button>
					</template>
				</el-table-column>
			</el-table>
		</el-card>
		<EditColumn ref="editColumnRef" :title="state.editcommonTitle" @handleQuery="handleQuery" />
	</div>
</template>
<script lang="ts" setup name="cms_common">
import { onMounted, reactive, ref } from 'vue';
import { ElMessageBox, ElMessage } from 'element-plus';
import EditColumn from '/@/views/CMS/cms_label/common/editLabel.vue';
import { Pagecms_Label, Delcms_Label } from '/@/api/CMS/cms_label';
const editColumnRef = ref<InstanceType<typeof EditColumn>>();
const state = reactive({
	loading: false,
	labelData: [] as Array<any>,
	queryParams: {
		name: undefined,
		code: undefined,
	},
	editcommonTitle: '',
});
onMounted(async () => {
	handleQuery();
});

// 打开编辑页面
const openEditType = (row: any) => {
	state.editcommonTitle = '编辑售后类型';
	editColumnRef.value?.openDialog(row);
};
// 重置操作
const resetQuery = () => {
	state.queryParams.name = undefined;
	state.queryParams.code = undefined;
	handleQuery();
};
// 打开新增页面
const openAddType = () => {
	state.editcommonTitle = '添加售后类型';
	editColumnRef.value?.openDialog({});
};
const handleQuery = async () => {
	state.loading = true;
	//调用接口查询类型数据
	let res = await Pagecms_Label(state.queryParams);
	state.labelData = res.data.result ?? [];
	state.loading = false;
};
// 删除当前行
const delType = (row: any) => {
	ElMessageBox.confirm(`确定删除售后类型：【${row.title}】?`, '提示', {
		confirmButtonText: '确定',
		cancelButtonText: '取消',
		type: 'warning',
	})
		.then(async () => {
			//调用接口删除类型
			await Delcms_Label(row);
			handleQuery();
			ElMessage.success('删除成功');
		})
		.catch(() => {});
};
</script>

<style></style>
